﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using myschoolDal;
//using myschoolmodels;
using studentManagementSystemModels;
using bug;

namespace school
{
    public partial class admin : Form
    {
        public static string role;
        public static long loginId;
        public static string loginPassword;

        public admin()
        {
            InitializeComponent();
        }

        private void role_comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private void role_comboBox_ControlAdded(object sender, EventArgs e)
        {

        }

        private void role_comboBox_MouseUp(object sender, EventArgs e)
        {

        }

        private void groupBox1_AutoSizeChanged(object sender, EventArgs e)
        {

        }

        private void admin_ControlRemoved(object sender, ControlEventArgs e)
        {

        }

        private void admin_BackgroundImageLayoutChanged(object sender, EventArgs e)
        {

        }

        private void role_comboBox_DragDrop(object sender, DragEventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void role_comboBox_ControlAdded(object sender, ControlEventArgs e)
        {

        }

        private void role_comboBox_MouseUp(object sender, MouseEventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            //获取身份信息
            if (psd_textBox.Text.Trim() == "" || name_textBox.Text.Trim() == "" || role_comboBox.SelectedItem == null)
            {
                MessageBox.Show("错误：" + bug.Class1.worng4001 + " \n错误代码：Wrong4001", "提示");
                //return button1_Click(object sender, EventArgs e);
            }
            else
            {
                loginId = Convert.ToInt64(name_textBox.Text.Trim());
                loginPassword = psd_textBox.Text.Trim();
                role = this.role_comboBox.SelectedItem.ToString();

                if (role == "学生")
                {
                    //检查账号密码
                    //账号密码均存在                    
                    if (stuservers.StuLoginCheck(loginId, loginPassword))
                    //if(true)
                    {
                        studesktop mainframe = new studesktop();
                        mainframe.BringToFront();
                        mainframe.Show();
                        this.Hide();
                    }

                    //检查账号不存在，或者密码错误
                    else if (!stuservers.StuLoginCheck(loginId, loginPassword))
                    {
                        MessageBox.Show("错误：" + bug.Class1.worng4002 + " \n错误代码：Wrong4002", "提示");
                    }
                }
                else if (role == "管理员")
                {
                    //检查账号密码
                    //if(checkrole())
                    if (manserver.ManLoginCheck(loginId, loginPassword))
                    //if (true) // 测试使用
                    {
                        mandesktop mainframe = new mandesktop();
                        mainframe.BringToFront();
                        mainframe.Show();
                        this.Hide();
                    }
                    //检查账号不存在，或者密码错误
                    else if (!stuservers.StuLoginCheck(loginId, loginPassword))
                    {
                        MessageBox.Show("错误：" + bug.Class1.worng4002 + " \n错误代码：Wrong4002", "提示");
                    }
                }
            }

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
        }

        private void name_textBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void admin_Load(object sender, EventArgs e)
        {

        }
    }
}
